<?php
namespace Home\Controller;
use Think\Controller;
class LaoshiController extends CommonController {
	//老师中心
    public function laoshi_core()
    {
        //公共显示变量
        $this->public_xianshi();

        //预约订单显示
        $sql = "select t1.*,t2.face,t2.phone,t3.name from jz_to_ls_yuyue t1 inner join laoshi_user t2 on t1.ls_uid=t2.id inner join jiazhang_xuqiu t3 on t1.jz_uid=t3.uid where t1.ls_uid='{$_SESSION['id']}' and is_shenhe=0";
        $yuyues = M()->query($sql);
        $this->assign('yuyues',$yuyues);

       	$this->display();   
    }
    //老师预约订单 取消 删除
    public function ls_order_del()
    {
        if (IS_POST) {
            $id = I('post.id');
            $res = M('jz_to_ls_yuyue')->delete($id);
            if ($res) {
                 $arr = array(
                        'error' =>1,
                        'info'=>"取消成功"
                        );
                echo json_encode($arr);
            }else {
                 $arr = array(
                        'error' =>0,
                        'info'=>"取消失败"
                        );
                echo json_encode($arr);
            }
        }
    }
    //老师预约订单 接受 
    public function jieshou_on()
    {
        if (IS_POST) {
            $id = I('post.id');
            $res = M('jz_to_ls_yuyue')->where(array('id'=>$id))->setField('is_laoshi_on',1);
            if ($res) {
                 $arr = array(
                        'error' =>1,
                        'info'=>"接受成功,请尽快连接课程顾问,尽快连接学生上课"
                        );
                echo json_encode($arr);
            }else {
                 $arr = array(
                        'error' =>0,
                        'info'=>"接受失败,重新在接受"
                        );
                echo json_encode($arr);
            }
        }
    }
    //老师  我的课程
    public function laoshi_core_order()
    {
        //公共显示变量
        $this->public_xianshi();

        //我的订单显示
        $sql = "select t1.*,t2.phone,t3.name from jz_to_ls_yuyue t1 inner join jiazhang_user t2 on t1.jz_uid=t2.id inner join jiazhang_xuqiu t3 on t1.jz_uid=t3.uid where t1.ls_uid='{$_SESSION['id']}' and is_shenhe=1";
        $orders = M()->query($sql);
        $this->assign('orders',$orders);

       $this->display();
    }

    //老师签到总结
    public function qiandaozj()
    {
        $id = I('get.id');
        $this->assign('id',$id);

        if (IS_POST) {
            $data['kec_id'] = I('post.kec_id');
            $data['date'] = I('post.start');
            $data['keshi'] = I('post.sk_num');
            $data['zongjie'] = I('post.zongjie');
            $data['addtime'] = time();

            //检测课时 已上课时跟签到课时对比
            $kechenginfo = M('jz_to_ls_yuyue')->where(['id'=>$data['kec_id']])->find();
            $yishang_ks = M('jz_sign')->sum('keshi');
            if ($kechenginfo['yishang_ks'] < $yishang_ks ) {
                $arr = array(
                    'error' =>0,
                    'info' => '您还有课程家长没签到哦'  
                    );
                echo json_encode($arr);
                exit;
            }
            //检测课时总数
            if ($kechenginfo['yishang_ks'] + $data['keshi'] > $kechenginfo['zong_ks'] ) {
                $arr = array(
                    'error' =>0,
                    'info' => '课时不足,请联系家长续课'  
                    );
                echo json_encode($arr);
                exit;
            }

            //入库
            $res = M('jz_sign')->add($data);
            if ($res) {

                //课时数 在订单中自动减去  老师签到自动减(先注销)
                // $yishang_ks = $kechenginfo['yishang_ks'] + $data['keshi'];
                // $shengyu_ks = $zong_ks - $yishang_ks;
                // $keshis = array('shengyu_ks'=>$shengyu_ks,'yishang_ks'=>$yishang_ks);
                // M('jz_to_ls_yuyue')->where(['id'=>$data['kec_id']])->setField($keshis);

                // //剩余课时小于等于3 自动发信息到会员手机
                // $js_phone = M('jiazhang_user')->where(array('id'=>$kechenginfo['jz_uid']))->getField('phone');//家长手机
                // if ($shengyu_ks < 4) {
                //     kes_miaodi($js_phone);
                // }

                //老师提交签到 自动通知家长签到
                $js_phone = M('jiazhang_user')->where(array('id'=>$kechenginfo['jz_uid']))->getField('phone');//家长手机
                $moban = "【老师上门】授课结束签到通知：".$data['date']."日老师授课已结束,请家长登陆网站平台确认签到。";
                tongz_miaodi($js_phone,$moban);

                $arr = array(
                    'error' =>1,
                    'info' => '签到成功'  
                    );
                echo json_encode($arr);
            }else{
                $arr = array(
                    'error' =>0,
                    'info' => '签到失败'  
                    );
                echo json_encode($arr);
            }
 
        }else {

            //最近一次授课
            $shouk_zj = M('jz_sign')->where(['kec_id'=>$id])->order('addtime desc')->find();
            $this->assign('shouk_zj',$shouk_zj);

            //所有授课
            $signs = M('jz_sign')->where(['kec_id'=>$id])->order('addtime desc')->select();
            $this->assign('signs',$signs);

            $this->display();
        }
        
    }
    //通知家长签到
    public function tongzjz()
    {
        if (IS_POST) {
            $id = I('post.id');
            //查询授课签到信息
            $signs = M('jz_sign')->where(['id'=>$id])->find();
            //查询家长手机
            $jz_uid = M('jz_to_ls_yuyue')->where(['id'=>$signs['kec_id']])->getField('jz_uid');
            if ($jz_uid) {
                $js_phone = M('jiazhang_user')->where(array('id'=>$jz_uid))->getField('phone');
                //老师提交签到 自动通知家长签到
                $moban = "【老师上门】授课结束签到通知：".$signs['date']."日老师授课已结束,请家长登陆网站平台确认签到。";
                tongz_miaodi($js_phone,$moban);

                $arr = array(
                    'error' =>1,
                    'info' => '发送成功'  
                    );
                echo json_encode($arr); 
            }else {
                $arr = array(
                    'error' =>0,
                    'info' => '发送失败'  
                    );
                echo json_encode($arr); 
            }
        }
    }


	//资料认证
    public function zlrz()
    { 
        //公共显示变量
        $this->public_xianshi();

    	//老师详细信息
        $laoshi_info = M('laoshi_user')->where(array('id'=>$_SESSION['id']))->find();
        $this->assign('laoshi_info',$laoshi_info);

        $this->display();
       
    }
    //资料认证 姓名姓别 修改
    public function name()
    { 
       if (IS_POST) {
        //昵称姓名入库
        $data['sfz_name'] = I('post.sfz_name');
        $data['sex'] = I('post.sex');

        //默认头像
        if ($data['sex'] == '男') {
            $data['face'] = "/Uploads/face/man.jpg";
        }else {
            $data['face'] = "/Uploads/face/woman.jpg";
        }
        
        //昵称验证
        if (empty($data['sfz_name'])) { 
            $arr = array(
                'error' =>0,
                'info' => '请输入正确的姓名'    
                );
            echo json_encode($arr);
            exit;
        }
        //入库
        $res = M('laoshi_user')->where(array('id'=>$_SESSION['id']))->setField($data);
            if ($res) {
                $arr = array(
                    'error' =>1,
                    'info' => '保存成功'  
                    );
                echo json_encode($arr);
            }else{
                $arr = array(
                    'error' =>0,
                    'info' => '保存失败'  
                    );
                echo json_encode($arr);
            }
       }
    }
	//资料认证 身份证号码修改
    public function sfz_num()
    { 
       if (IS_POST) {
       	//身份证姓名入库
       	$data['sfz_num'] = I('post.sfz');
        //身份证
        $sfz_yz = preg_match("/^(\d{18,18}|\d{15,15}|\d{17,17}x)$/",$data['sfz_num']);
        if (!$sfz_yz) {
        	$arr = array(
        		'error' =>0,
        		'info' => '请输入正确的身份证号'	
        		);
        	echo json_encode($arr);
        	exit;
        }
        //入库
        $res = M('laoshi_user')->where(array('id'=>$_SESSION['id']))->setField('sfz_num',$data['sfz_num']);
	        if ($res) {
	        	$arr = array(
	        		'error' =>1,
	        		'info' => '身份证号修改成功'	
	        		);
	        	echo json_encode($arr);
	        }else{
	        	$arr = array(
	        		'error' =>0,
	        		'info' => '身份证号修改失败'	
	        		);
	        	echo json_encode($arr);
	        }
       }
    }
    //资料认证 身份证照片修改
    public function sfz_img()
    {$city = I('get.newcity');
		if(!empty($_FILES['file']['tmp_name'])){
			$upload = new \Think\Upload();// 实例化上传类    
		    $upload->maxSize   =     3145728 ;// 设置附件上传大小    
		    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
		    $upload->savePath  =      'Uploads/'; // 设置附件上传目录    
		    // 上传单个文件     
		    $info   =   $upload->uploadOne($_FILES['file']);    
		    if(!$info) {// 上传错误提示错误信息        
				//$this->error($upload->getError());
		    }else{
		    // 上传成功 获取上传文件信息         
		    	$face =  '/Uploads'.'/'.$info['savepath'].$info['savename'];   
		    	//echo $face; 
		    	//原图入库赋值
				//$data['face'] = $face;
				M('laoshi_user')->where(array('id'=>$_SESSION['id']))->setField('sfz_img',$face);
		    }
		}
		$this->redirect('laoshi/zlrz',array('newcity'=>$city));
    }

    //资料认证 银行卡
    public function bank()
    {
        //公共显示变量
        $this->public_xianshi();

        $bank = M('bank')->where(array('uid'=>$_SESSION['id']))->find();
        $this->assign('bank',$bank);

        $this->display();
    }
    //资料认证 银行卡添加/修改
    public function bank_add()
    {   //[bank_name] => 11[bank_addr] => xxx[bank] => 中国工商银行[bank_num] => 1111111111111111[uid] => 2[is_who] => laoshi
        if (IS_POST) {
            $data['uid'] = I('post.uid');
            $data['is_who'] = I('post.is_who');

            $data['bank_name'] = I('post.bank_name');
            $data['bank_addr'] = I('post.bank_addr');
            $data['bank'] = I('post.bank');
            $data['bank_num'] = I('post.bank_num');

            $str = "/^(\d{16}|\d{19})$/";
            $bank_num_yz = preg_match($str, $data['bank_num']);
             if (!$bank_num_yz) {
                $arr = array(
                    'error' => 0,
                    'info' => '请输入正确的银行卡号'
                    );
                echo json_encode($arr);
                exit;
             }

            //检测是否绑定银行卡 存在 跟新 不存在 添加 
            $uid = M('bank')->where(array('uid'=>$data['uid']))->find();
            if ($uid) {
                $res = M('bank')->where(array('uid'=>$data['uid']))->save($data);
                if ($res) {
                    $arr = array(
                        'error' => 1,
                        'info' => '更新成功'    
                        );
                    echo json_encode($arr);
                }else {
                    $arr = array(
                        'error' => 0,
                        'info' => '更新失败'    
                        );
                    echo json_encode($arr);
                }
            }else {
                $res = M('bank')->add($data);
                if ($res) {
                    $arr = array(
                        'error' => 1,
                        'info' => '添加成功'    
                        );
                    echo json_encode($arr);
                }else {
                    $arr = array(
                        'error' => 0,
                        'info' => '添加失败'    
                        );
                    echo json_encode($arr);
                }
            }
        }   
    }

    //资料认证 教师证
    public function zlrz_jsz()
    {
        //公共显示变量
        $this->public_xianshi();

    	//老师详细信息
       $jiaoshizheng_img = M('laoshi_user')->where(array('id'=>$_SESSION['id']))->getField('jiaoshizheng_img');
       $this->assign('jiaoshizheng_img',$jiaoshizheng_img);

       	$this->display();
    }
    //资料认证 教师证修改
    public function jiaoshizheng_img()
    {$city = I('get.newcity');
		if(!empty($_FILES['file']['tmp_name'])){
			$upload = new \Think\Upload();// 实例化上传类    
		    $upload->maxSize   =     3145728 ;// 设置附件上传大小    
		    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
		    $upload->savePath  =      'Uploads/'; // 设置附件上传目录    
		    // 上传单个文件     
		    $info   =   $upload->uploadOne($_FILES['file']);    
		    if(!$info) {// 上传错误提示错误信息        
				//$this->error($upload->getError());
		    }else{
		    // 上传成功 获取上传文件信息         
		    	$face =  '/Uploads'.'/'.$info['savepath'].$info['savename'];   
				M('laoshi_user')->where(array('id'=>$_SESSION['id']))->setField('jiaoshizheng_img',$face);
		    }
		}
		$this->redirect('laoshi/zlrz_jsz',array('newcity'=>$city));
    }

    //资料认证 其它证件
    public function zlrz_qtzj()
    {
        //公共显示变量
        $this->public_xianshi();


       	$this->display();
    }
    //资料认证 其它证件 毕业证/学位证  修改
    public function qitazheng_img()
    {$city = I('get.newcity');
		if(!empty($_FILES['file']['tmp_name'])){
			$upload = new \Think\Upload();// 实例化上传类    
		    $upload->maxSize   =     3145728 ;// 设置附件上传大小    
		    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
		    $upload->savePath  =      'Uploads/'; // 设置附件上传目录    
		    // 上传单个文件     
		    $info   =   $upload->uploadOne($_FILES['file']);    
		    if(!$info) {// 上传错误提示错误信息        
				//$this->error($upload->getError());
		    }else{
		    // 上传成功 获取上传文件信息         
		    	$face =  '/Uploads'.'/'.$info['savepath'].$info['savename'];   
				M('laoshi_user')->where(array('id'=>$_SESSION['id']))->setField('qitazheng_img',$face);
		    }
		}
		$this->redirect('laoshi/zlrz_qtzj',array('newcity'=>$city));
    }

	//头像 修改
    public function zlrz_head()
    {
        //公共显示变量
        $this->public_xianshi();

    	//老师头像
       $laoshi_face = M('laoshi_user')->where(array('id'=>$_SESSION['id']))->getField('face');
       $this->assign('laoshi_face',$laoshi_face);
       	$this->display();   
    }
    //资料认证 其它证件 毕业证/学位证  修改
    public function face()
    {$city = I('get.newcity');
		if(!empty($_FILES['file']['tmp_name'])){
			$upload = new \Think\Upload();// 实例化上传类    
		    $upload->maxSize   =     3145728 ;// 设置附件上传大小    
		    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
		    $upload->savePath  =      'Uploads/'; // 设置附件上传目录    
		    // 上传单个文件     
		    $info   =   $upload->uploadOne($_FILES['file']);    
		    if(!$info) {// 上传错误提示错误信息        
				//$this->error($upload->getError());
		    }else{
		    // 上传成功 获取上传文件信息         
		    	$face =  '/Uploads'.'/'.$info['savepath'].$info['savename'];   
				M('laoshi_user')->where(array('id'=>$_SESSION['id']))->setField('face',$face);
		    }
		}
		$this->redirect('laoshi/zlrz_head',array('newcity'=>$city));
    }

    //自我介绍
    public function introduce()
    {
        //公共显示变量
        $this->public_xianshi();
        $jiaoling_jli = M('jiaoling_jli')->where(array('uid'=>$_SESSION['id']))->find();
        $this->assign('jiaoling_jli',$jiaoling_jli);


    	$this->display();
    }
    //自我介绍 编辑器图片上传
    // public function img()
    // {
    //     //print_r($_POST);
    //     $upload = new \Think\Upload();// 实例化上传类    
    //     $upload->maxSize   =     3145728 ;// 设置附件上传大小    
    //     $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
    //     $upload->savePath  =      'Uploads/edit/'; // 设置附件上传目录    
    //     // 上传文件     
    //     $info   =   $upload->upload();    
    //     if(!$info) {// 上传错误提示错误信息         
    //         $arr = array(
    //         'code' => 0,
    //         'msg' => $upload->getError(),
    //         );
    //         echo json_encode($arr);
 
    //     }else{// 上传成功   
    //         $info = current($info);//减维 
    //         $url =  __ROOT__.'/'.'Uploads/'.$info['savepath'].$info['savename'];    

    //         $arr = array(
    //         'code' => 0,
    //         'msg' => '上传成功',
    //         'data'=> array(
    //             'src' => $url,
    //             'title' => $info['savename']
    //             )
    //         );
    //         echo json_encode($arr);
    //     }
    // }

    //自我介绍 教龄/经历添加
    public function introduce_add()
    {
        if (IS_POST) {
            $data['jiaoling'] = I('post.jiaoling');

            $data['start_year'] = I('post.start_year');
            $data['start_month'] = I('post.start_month');
            $data['stop_year'] = I('post.stop_year');
            $data['stop_month'] = I('post.stop_month');

            $data['experience'] = I('post.content');
            $data['uid'] = $_SESSION['id'];
            $data['create_time'] = time();

            //检测老师经历存在 跟新 不存在 添加 
            $uid = M('jiaoling_jli')->where(array('uid'=>$_SESSION['id']))->find();
            if ($uid) {
                $res = M('jiaoling_jli')->where(array('uid'=>$_SESSION['id']))->save($data);
                if ($res) {
                    $arr = array(
                        'error' => 1,
                        'info' => '更新成功'    
                        );
                    echo json_encode($arr);
                }else {
                    $arr = array(
                        'error' => 0,
                        'info' => '更新失败'    
                        );
                    echo json_encode($arr);
                }
            }else {
                $res = M('jiaoling_jli')->add($data);
                if ($res) {
                    $arr = array(
                        'error' => 1,
                        'info' => '添加成功'    
                        );
                    echo json_encode($arr);
                }else {
                    $arr = array(
                        'error' => 0,
                        'info' => '添加失败'    
                        );
                    echo json_encode($arr);
                }
            }


        }
    }


    //自我介绍  自我描述
    public function describe()
    {
        //公共显示变量
        $this->public_xianshi();

        $jiaoling_jli = M('jiaoling_jli')->where(array('uid'=>$_SESSION['id']))->getField('jianjie');
        $this->assign('jiaoling_jli',$jiaoling_jli);

    	$this->display();
    }
    //自我描述 添加
    public function describe_add()
    {
        //print_r($_POST);
        if (IS_POST) {
            $jianjie = I('post.content');

            $res = M('jiaoling_jli')->where(array('uid'=>$_SESSION['id']))->setField('jianjie',$jianjie);
            if ($res) {
                $arr = array(
                    'error' => 1,
                    'info' => '添加成功'    
                    );
                echo json_encode($arr);
            }else {
                $arr = array(
                    'error' => 0,
                    'info' => '添加失败'    
                    );
                echo json_encode($arr);
            }
        }
        

    }

    //自我介绍  自的关键字
    public function keyword()
    {
        //公共显示变量
        $this->public_xianshi();

        //学生类型
        $jiaoling_jli_stye = M('jiaoling_jli')->where(array('uid'=>$_SESSION['id']))->getField('stu_stye');
        $jiaoling_jli_stye = explode(',', $jiaoling_jli_stye);
        $this->assign('jiaoling_jli_stye',$jiaoling_jli_stye);

        //老师特点
        $jiaoling_jli_tedian = M('jiaoling_jli')->where(array('uid'=>$_SESSION['id']))->getField('laoshi_stye');
        $jiaoling_jli_tedian = explode(',', $jiaoling_jli_tedian);
        $this->assign('jiaoling_jli_tedian',$jiaoling_jli_tedian);      

    	$this->display();
    }
    //自的关键字 学生类型添加
    public function keyword_stye_add()
    {
        //print_r($_POST);
        if (IS_POST) {
            $stu_stye = I('post.stye_one').','.I('post.stye_two').','.I('post.stye_three');
            $res = M('jiaoling_jli')->where(array('uid'=>$_SESSION['id']))->setField('stu_stye',$stu_stye);
            if ($res) {
                $arr = array(
                    'error' => 1,
                    'info' => '添加成功'    
                    );
                echo json_encode($arr);
            }else {
                $arr = array(
                    'error' => 0,
                    'info' => '添加失败'    
                    );
                echo json_encode($arr);
            }
        }
    }
    //自的关键字 老师特点添加
    public function keyword_tedian_add()
    {
        if (IS_POST) {
            $laoshi_stye = I('post.tedian_one').','.I('post.tedian_two').','.I('post.tedian_three');
            $res = M('jiaoling_jli')->where(array('uid'=>$_SESSION['id']))->setField('laoshi_stye',$laoshi_stye);
            if ($res) {
                $arr = array(
                    'error' => 1,
                    'info' => '添加成功'    
                    );
                echo json_encode($arr);
            }else {
                $arr = array(
                    'error' => 0,
                    'info' => '添加失败'    
                    );
                echo json_encode($arr);
            }
        }
    }

    //自我介绍  成功案例
    public function sussess_case()
    {
        //公共显示变量
        $this->public_xianshi();

        //最近的成功案例显示
        $success_case = M('success_case')->where(array('uid'=>$_SESSION['id']))->order('create_time desc')->find();
        $this->assign('success_case',$success_case);

    	$this->display();
    }
    //成功案例 添加
    public function sussess_case_add()
    {
    //[year] => 1983[month] => 6[stu_name] => 撒发[stu_addr] => asfda[content] => aa[file] => 
        if (IS_POST) {
            $data['uid'] = $_SESSION['id'];

            $data['time_year'] = I('post.year');
            $data['time_month'] = I('post.month');
            $data['stu_name'] = I('post.stu_name');
            $data['school'] = I('post.stu_addr');
            $data['result'] = I('post.content');
            $data['create_time'] = time();

            $res = M('success_case')->add($data);
            if ($res) {
                $arr = array(
                    'error' => 1,
                    'info' => '添加成功'    
                    );
                echo json_encode($arr);
            }else {
                $arr = array(
                    'error' => 0,
                    'info' => '添加失败'    
                    );
                echo json_encode($arr);
            }

        }
    }

    //自我介绍  学历院校  
    public function school()
    {
        //公共显示变量
        $this->public_xianshi();
        //学历信息显示
        $school_info = M('laoshi_user')->where(array('id'=>$_SESSION['id']))->field('education,sfz_name,school,major')->find();
        $this->assign('school_info',$school_info);


    	$this->display();
    }
    //学历院校  信息添加
    public function school_add()
    {
    //[xueli] => 本科[stu_name] => s[stu_addr] => a[major] => a
        if (IS_POST) {
            $data['education'] = I('post.xueli');
            $data['school'] = I('post.stu_addr');
            $data['major'] = I('post.major');

            $res = M('laoshi_user')->where(array('id'=>$_SESSION['id']))->save($data);
            if ($res) {
                $arr = array(
                    'error' => 1,
                    'info' => '添加成功'    
                    );
                echo json_encode($arr);
            }else {
                $arr = array(
                    'error' => 0,
                    'info' => '添加失败'    
                    );
                echo json_encode($arr);
            }
        }
    }

    //授课信息  
    public function teaching()
    {
        //公共显示变量
        $this->public_xianshi();

        //两大类
        $whs = M('grade')->where(array('parent_id'=>0))->select();
        $this->assign('whs',$whs);
        //获取年级选择的
        $wh = I('get.wh')?I('get.wh'):'文化语言';
        $this->assign('wh',$wh);

        if ($wh == '文化语言') {
            //年级
            $grades = M('grade')->where(array('parent_id'=>1))->select();
            $this->assign('grades',$grades);
            //获取年级选择的
            $grade_name = I('get.grade')?I('get.grade'):'小学';
            $this->assign('grade_name',$grade_name);

            //课程显示 根据年级显示课程
            $gradeid = M('grade')->where(array('grade_name'=>$grade_name))->getField('gradeid');
            $kecheng = M('grade')->where(array('parent_id'=>$gradeid))->select();
            $this->assign('kecheng',$kecheng);
            //获取课程科目选择的
            $subject_name = I('get.subject')?I('get.subject'):'语文';
            $this->assign('subject_name',$subject_name);
        }else {
            //艺术课程 二级类
            $grades = M('grade')->where(array('parent_id'=>2))->select();
            $this->assign('grades',$grades);
            //获取年级选择的
            $grade_name = I('get.grade')?I('get.grade'):'小学';
            $this->assign('grade_name',$grade_name);

            //课程显示 根据年级显示课程
            $gradeid = M('grade')->where(array('grade_name'=>$grade_name))->getField('gradeid');
            $kecheng = M('grade')->where(array('parent_id'=>$gradeid))->select();
            $this->assign('kecheng',$kecheng);
            //获取课程科目选择的
            $subject_name = I('get.subject')?I('get.subject'):'语文';
            $this->assign('subject_name',$subject_name);
        }

        //获取老师授课城市
        $laoshi_quyu = M('laoshi_user')->where(array('id'=>$_SESSION['id']))->getField('city');
        $cityid = M('city')->where(array('city_name'=>$laoshi_quyu))->getField('cityid');
    	//授课城市区域显示
    	$city_quyu = M('city')->where(array('parent_id'=>$cityid))->select();
    	$this->assign('city_quyu',$city_quyu);


    	//授课方式显示
    	$method_info = M('teachingmethod')->select();
    	$this->assign('method_info',$method_info);

        //老师授课信息显示
        $showke_info = M('showke_info')->where(array('uid'=>$_SESSION['id']))->find();
        $this->assign('showke_info',$showke_info);

        //$showke_info['methods']转数组
        $methods = explode(',', $showke_info['methods']);
        $this->assign('methods',$methods);

        //$showke_info['shouke_time']转数组
        $shouke_times = explode(',', $showke_info['shouke_time']);
        $this->assign('shouke_times',$shouke_times);

    	//授课时间段显示 上午
    	$showke_time_sw = M('showke_time')->where(array('time_name'=>'上午'))->select();
    	$this->assign('showke_time_sw',$showke_time_sw);
        //授课时间段显示 下午
        $showke_time_xw = M('showke_time')->where(array('time_name'=>'下午'))->select();
        $this->assign('showke_time_xw',$showke_time_xw);
        //授课时间段显示 晚上
        $showke_time_ws = M('showke_time')->where(array('time_name'=>'晚上'))->select();
        $this->assign('showke_time_ws',$showke_time_ws);


    	$this->display();
    }

    //授课信息 添加
    public function teaching_add()
    {   
    	//Array ( [sk_city] => 1 [subject] => 语文 [address] => 地铁三号线 [price] => 190 [grade] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) [sm_fangshi] => 3 [content] => 周末全天 [file] => )    [sm_shijian] => Array([0] => 1[1] => 4[2] => 10[3] => 13[4] => 2[5] => 5[6] => 14)
        if (IS_POST) {
            $data['uid'] = $_SESSION['id'];

            $data['sk_city'] = I('post.sk_city');
            $data['subject'] = I('post.subject');
            $data['address'] = I('post.address');
            $data['price'] = I('post.price');

            $data['class'] = I('post.wh');
            $data['grades'] = I('post.grades');
            $data['subject'] = I('post.subject');

            $sm_fangshi = implode(',', I('post.sm_fangshi'));
            $data['methods'] = $sm_fangshi;

            //授课时间段id
            $sm_shijian = implode(',', I('post.sm_shijian'));
            $data['shouke_time'] = $sm_shijian;

            //检测老师授课信息存在 跟新 不存在 添加 
            $uid = M('showke_info')->where(array('uid'=>$_SESSION['id']))->find();
            if ($uid) {
                $res = M('showke_info')->where(array('uid'=>$_SESSION['id']))->save($data);
                if ($res) {
                    $arr = array(
                        'error' => 1,
                        'info' => '更新成功'    
                        );
                    echo json_encode($arr);
                }else {
                    $arr = array(
                        'error' => 0,
                        'info' => '更新失败'    
                        );
                    echo json_encode($arr);
                }
            }else {
                $res = M('showke_info')->add($data);
                if ($res) {
                    $arr = array(
                        'error' => 1,
                        'info' => '添加成功'    
                        );
                    echo json_encode($arr);
                }else {
                    $arr = array(
                        'error' => 0,
                        'info' => '添加失败'    
                        );
                    echo json_encode($arr);
                }
            }
        }
    }

    //账号信息 
    public function zhanghao()
    {
        //公共显示变量
        $this->public_xianshi();

        $this->display();
    }
    //账号信息 密码重置
    public function zhanghao_add()
    {
        //Array ( [password] => qq [newpassword] => qq [renewpassword] => qq )
        if (IS_POST) {
            $password = I('post.password');
            $newpassword = I('post.newpassword');
            $renewpassword = I('post.renewpassword');

            //验证原始密码
            $password_yz = M('laoshi_user')->where(array('id'=>$_SESSION['id']))->getField('password');
            if (md5($password) != $password_yz) {
                $arr = array(
                    'error' =>0,
                    'info' =>'原密码输入有误'
                    );
                echo json_encode($arr);
                exit;
            }

            //新密码 验证
            $preg_password = "/^[0-9A-z]{6,16}$/";
            $password_Yz = preg_match($preg_password, $newpassword);
            if (!$password_Yz) {
                $arr = array(
                    'error' => 0,
                    'info' => '密码必须是6-16位的字符串'
                    );
                echo json_encode($arr);
                exit;
            }

            //第二次密码跟第一次检测
            if ($newpassword != $renewpassword) {
                $arr = array(
                    'error' => 0,
                    'info' => '两次密码输入不一样'
                    );
                echo json_encode($arr);
                exit;
            }

            //更新
            $res = M('laoshi_user')->where(array('id'=>$_SESSION['id']))->setField('password',md5($newpassword));
            if ($res) {
                $arr = array(
                    'error' => 1,
                    'info' => '更新成功,需要重新登陆'    
                    );
                echo json_encode($arr);
            }else {
                $arr = array(
                    'error' => 0,
                    'info' => '更新失败'    
                    );
                echo json_encode($arr);
            }
        }
    }


    //我的账户信息显示
    public function laoshi_core_zhanghao()
    {
        //公共显示变量
        $this->public_xianshi();

        //更新 第二天拆红包
        $time = time(); 
        $date_time = date('Y-m-d',$time);//当日
        $dr_time = strtotime($date_time);
        $this->assign('dr_time',$dr_time);

        //账户详细信息
        $user_infos = M('user_price')->where(array('uid'=>$_SESSION['id']))->find();
        $this->assign('user_infos',$user_infos);

        $this->display();
    }






}